package com.dencycheng.rabbitmq.producer;

import com.dencycheng.rabbitmq.entity.Order;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author dencycheng
 * @date 2020/9/11 11:28
 */
@Component
public class OrderSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送
     *
     * @param order
     * @throws Exception
     */
    public void send(Order order) throws Exception {

        //消息唯一ID
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getMessageId());

        //发送
        rabbitTemplate.convertAndSend("order-exchange","order.abcda.dsda",order,correlationData);
    }
}
